package com.update.service.impl;

import com.common.basic.ResponseState;
import com.common.basic.Result;
import com.update.dao.ApkVersionDao;
import com.update.model.ApkVersion;
import com.update.service.ApkVersionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ApkVersionServiceImpl implements ApkVersionService {

    @Autowired
    private ApkVersionDao versionDao;

    @Transactional(readOnly = true)
    @Override
    public Result<ApkVersion> findById(Integer versionId) {
        Result<ApkVersion> result = new Result<>();
        if(versionId == null) {
            result.code = ResponseState.REQUEST_BUSINESS_ERROR;
            result.msg = "参数不能为空";
            return result;
        }
        result.data = versionDao.findById(versionId);
        result.code = ResponseState.REQUEST_SUCCESS;
        result.msg = "成功";
        return result;
    }

    @Transactional(readOnly = true)
    @Override
    public Result<ApkVersion> findByApkId(Integer apkId) {
        Result<ApkVersion> result = new Result<>();

        return result;
    }

    @Transactional
    @Override
    public Result save(ApkVersion apkVersion) {
        Result result = new Result();
        if(apkVersion == null) {
            result.msg = "参数不能为空";
            result.code = ResponseState.REQUEST_BUSINESS_ERROR;
            return result;
        }
        versionDao.save(apkVersion);
        result.code = ResponseState.REQUEST_SUCCESS;
        result.msg = "成功";
        return result;
    }

    @Transactional
    @Override
    public Result delete(Integer id) {
        Result result = new Result();
        if(id == null) {
            result.code = ResponseState.REQUEST_BUSINESS_ERROR;
            result.msg = "参数不能为空";
            return result;
        }
        versionDao.delete(id);
        result.code = ResponseState.REQUEST_SUCCESS;
        result.msg = "成功";
        return result;
    }

    @Transactional
    @Override
    public Result update(ApkVersion apkVersion) {
        Result result = new Result();
        if(apkVersion == null) {
            result.msg = "参数不能为空";
            result.code = ResponseState.REQUEST_BUSINESS_ERROR;
            return result;
        }
        versionDao.update(apkVersion);
        result.code = ResponseState.REQUEST_SUCCESS;
        result.msg = "成功";
        return result;
    }
}
